package com.desmart.ht;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.desmart.ht.view.TabAdapter;

import java.util.ArrayList;
import java.util.List;

public class ShareActivity extends BaseActivity implements View.OnClickListener {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<String> titles = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    private View vBack;

    public static void start(Context context){
        Intent intent = new Intent(context,ShareActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);
        initViews();
        initTabs();
    }

    private void initTabs() {
        titles.add("分享给我");
        titles.add("我分享的");
        fragments.add(Fragment.instantiate(this,ShareFragment.class.getName()));
        fragments.add(Fragment.instantiate(this,ShareFragment.class.getName()));

        for (String title : titles){
            tabLayout.addTab(tabLayout.newTab().setText(title));
        }

        TabAdapter tabAdapter = new TabAdapter(getSupportFragmentManager(), fragments, titles);
        viewPager.setAdapter(tabAdapter);
        tabLayout.setupWithViewPager(viewPager);

    }

    private void initViews() {
        tabLayout = findViewById(R.id.tablayout);
        viewPager = findViewById(R.id.viewpager);
        TextView tvTitle = findViewById(R.id.common_content_tv);
        vBack = findViewById(R.id.common_back_iv);
        vBack.setOnClickListener(this);
        tvTitle.setText("分享");
    }

    @Override
    public void onClick(View view) {
        if (view == vBack){
            onBackPressed();
        }
    }
}
